<?php include_once "top.php";
$shoper=$db->ig2_want('mae_user','id='.$_GET['id'].' and is_delete=0');

//if(!$shoper || $shoper['role_type']!=1)
	//tellgoto('','user.php');
$shop=$db->ig2_want('mae_shop','admin_id="'.trim($shoper['id']).'"');
// 取得上月增长率
$nowtime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
$currentYear = date('Y', strtotime($nowtime));
$growthRate = $db->ig2_want('mae_growth_rate', 'shopid = '.$shop['id'].' AND statyear = "'.$currentYear.'"');

// 上月城市排名
$shops = $db->ig2_query_select('SELECT id, prev_month_count FROM mae_shop WHERE `is_activate`=1 and  city_id="'.$shop['city_id'].'" ORDER BY prev_month_count DESC');
$ranking = 1;
foreach($shops as $target) {
    if ($target['id'] != $shop['id']) {
        $ranking++;
    } else {
        break;
    }
}
// 判断门店是否在达标有奖活动分组内
$inActivity = false;
$activitySql = "SELECT rpa.* FROM mae_reach_prize_activity rpa";
$activitySql .= " INNER JOIN mae_rel_reach_prize_activity_group rrpag ON rpa.id = rrpag.activityid";
$activitySql .= " INNER JOIN mae_group g ON g.id = rrpag.groupid";
$activitySql .= " INNER JOIN mae_rel_group_shop rgs ON rgs.groupid = g.id";
$activitySql .= " INNER JOIN mae_shop s ON s.id = rgs.shopid";
$activitySql .= " WHERE s.id = ".$shop['id']." AND rpa.status = 1 AND rpa.starttime <= ".time()." AND rpa.endtime >= ".time();

$activitySql .= " LIMIT 0,1";
$activity = $db->ig2_query_select($activitySql);

if ($activity) {
    $inActivity = true;
}
	
	$groupSql = "SELECT * FROM mae_group g";
	$groupSql .=" INNER JOIN mae_rel_festival_activity_group mrrpag ON mrrpag.groupid = g.id";
	$groupSql .= " INNER JOIN mae_festival_activity mrpa ON mrpa.id = mrrpag.activityid";
	$groupSql .= " INNER JOIN mae_rel_group_shop mrgs ON mrgs.groupid = g.id";
	$groupSql .= " INNER JOIN mae_shop s ON s.id = mrgs.shopid AND s.status = 1";
	$groupSql .= " INNER JOIN mae_user u ON u.id = s.admin_id AND u.is_delete = 0 AND mrpa.status= 1";
	$groupSql .= " WHERE u.id = ".$_GET['id']." AND u.role_type=1 AND mrpa.starttime <= ".time()." AND mrpa.endtime >= ".time() ;
	$groupSql .= " LIMIT 0,1";
	$activity_float = $db->ig2_query_select($groupSql);
	foreach($activity_float as $k=>$val ){
		$a=$val['activityname'];
		$b=$val['content'];   
		$activityid=$val['activityid'];
	}	
	
	//判断浮层活动弹窗的条件
   
	
    $statusSql = "SELECT * FROM mae_group g";
	$statusSql .=" INNER JOIN mae_rel_festival_activity_group mrrpag ON mrrpag.groupid = g.id";
	$statusSql .= " INNER JOIN mae_festival_activity mrpa ON mrpa.id = mrrpag.activityid";
	$statusSql .= " INNER JOIN mae_rel_group_shop mrgs ON mrgs.groupid = g.id";
	$statusSql .= " INNER JOIN mae_shop s ON s.id = mrgs.shopid AND s.status = 1";
	$statusSql .= " INNER JOIN mae_user u ON u.id = s.admin_id AND u.is_delete = 0 AND mrpa.status= 1";
	$statusSql .= " WHERE mrpa.status=1 AND u.id = ".$_GET['id']." AND u.role_type=1 AND mrpa.starttime <= ".time()." AND mrpa.endtime >= ".time() ;
    
   $status_q=$db->ig2_query_select($statusSql);
   
    $status_sql= "SELECT status FROM mae_festival_exchange_log where activityid=".$activityid." and userid=".$_GET['id']."";
    $status_query=$db->ig2_query_select1($status_sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width" />
    <meta content="telephone=no" name="format-detection" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>店长主页</title>
    <link href="css/discount.css" rel="stylesheet" type="text/css" />
    <link href="css/common.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="inc/jquery.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function(){
            x=parseInt($(window).innerWidth());
            y=parseInt($(window).innerHeight());
            p=720/x;

            $('#p2_3').click(function(){
                $('#p2box').width(x).css({left:0,top:0});
                $('.p1bg').width(x);
                $('#p2boxbt,#p2boxbt_2').width(203/p).height(76/p);
                $('#p2boxbt').css({left:452/p+'px',top:1019/p+'px'});
                $('#p2boxbt_2').css({left:69/p+'px',top:1019/p+'px'});
                $('#nm').css({left:248/p+'px',top:273/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
                $('#tel').css({left:248/p+'px',top:387/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
                $('#add').css({left:248/p+'px',top:502/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
                $('#shop_name').css({left:248/p+'px',top:616/p+'px',width:406/p+'px',lineHeight:64/p+'px',fontSize:24/p+'px',marginLeft:12/p+'px'});
                $('#p2box').fadeIn(500);
            });

            $('#market').click(function(){//兑换
                var shopownerid = $("#ownerid").val();
                window.location.href = 'shopowner_market.php?ownerid=' +　shopownerid;
            });
             $('#market_list').click(function(){//兑换
                var changeid = $("#ownerid").val();
                window.location.href = 'shop_change.php?ownerid=' + changeid;
            });
			

            //修改个人资料
            document.getElementById("p2boxbt").addEventListener("touchstart", touchStartp2boxbt, false);
            document.getElementById("p2boxbt").addEventListener("touchend", touchEndp2boxbt, false);
            function touchStartp2boxbt(event){
                startX = event.touches[0].clientX;
                document.getElementById('p2boxbt').src='images/p2boxbt_h.jpg';
            }
            function touchEndp2boxbt(event){
                endX = event.changedTouches[0].clientX;
                document.getElementById('p2boxbt').src='images/p2boxbt.jpg';
            }

            $('#p2boxbt').click(function(){
                document.getElementById('p2boxbt').src='images/p2boxbt_h.jpg';
                setTimeout("document.getElementById('p2boxbt').src='images/p2boxbt.jpg'",1000);
                if(check()){
                    var id='<?php echo $shoper['id']?>';
                    var name=$('#nm').val();
                    var phone=$('#tel').val();
                    var address=$('#add').val();
                    $.ajax({
                        type: "GET",
                        url: "ra_ajax.php?update_user=1&id="+id+"&name="+name+"&phone="+phone+"&address="+address,
                        success: function(data){
                            if(data == 'success'){
                                alert('修改成功');
                                $('#xm').html(name);
                                $('#p2box').fadeOut(500);
                            }
                            getWidth();
                        }
                    });
                }
            });

            //取消修改个人资料
            document.getElementById("p2boxbt_2").addEventListener("touchstart", touchStartp2boxbt_2, false);
            document.getElementById("p2boxbt_2").addEventListener("touchend", touchEndp2boxbt_2, false);
            function touchStartp2boxbt_2(event){
                startX = event.touches[0].clientX;
                document.getElementById('p2boxbt_2').src='images/p2boxbt_2_h.jpg';
            }
            function touchEndp2boxbt_2(event){
                endX = event.changedTouches[0].clientX;
                document.getElementById('p2boxbt_2').src='images/p2boxbt_2.jpg';
            }

            $('#p2boxbt_2').click(function(){
                $('#p2box').fadeOut(500);
                $('#nm').val('<?php echo $shoper['name']?>');
                $('#tel').val('<?php echo $shoper['phone']?>');
                $('#add').val('<?php echo $shoper['address']?>');
            });

            setTimeout("popup()", 1000);

            $(".cancel1").click(function(){
                $(".pop_mask").fadeOut(500);
                $("#cancel_con1").fadeOut(500);
            });

            $(".cancel2").click(function(){
                $(".pop_mask").fadeOut(500);
                $("#cancel_con2").fadeOut(500);
            });

            $(".cancel3").click(function(){
                $(".pop_mask").fadeOut(500);
                $("#cancel_con3").fadeOut(500);
            });
			
			//新添加
			$(".cancel3").click(function(){
                $(".pop_mask").fadeOut(500);
                $("#cancel_con4").fadeOut(500);
            });
            
            
            <?php  if($status_query=="" && $status_q!=""){?>
            
   	        var popupWidth =  $(".shopowner_body").width();
            var windowWidth =  $(window).outerWidth();
            var windowHeight =  $(window).outerHeight();
            var popupHeight = $("#cancel_con4").height();
            $(".pop_mask").fadeIn(500);
		$("#cancel_con4").css({"position":"absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow"); 
            
            <?php }?>
            $(".botton").click(function(){			
				if($(this).attr('dd')){ 
					$('.botton').val($(this).attr('dd'));
				}	
					var url = "float.php";
					var data = {status:$('.botton').val(),userid:$("#ownerid").val(),activityid:$("#activityid").val()};
					$.get(url,data,function(){
						$(".pop_mask").fadeOut(500);
						$("#cancel_con4").fadeOut(500);	
					});
					
					
				});
            
            
        });

        function check(){
            if(trim(document.getElementById('nm').value)==''){
                alert('请输入姓名')
                return false;
            }

            var phone=document.getElementById('tel').value;
            var myregPhone = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i;
            if(trim(phone)==''){
                alert('请输入电话');
                return false;
            }else{
                if(!myregPhone.test(phone)){
                    alert('请输入正确的电话号');
                    return false;
                }
            }

            if(trim(document.getElementById('add').value)==''){
                alert('请输入地址');
                return false;
            }

            return true;
        }

        function popup() {
            // 如果是一号，并且上月销售达到奖励指标，则弹出奖励浮层，否则弹出售油积分规则浮层。
            var popupEncourage = false;
            var addscore = 0;
            var date = new Date();
            var today = date.getDate();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;

            // 前一个月
            if (month == 1) {
                month = "12";
                year = year - 1;
            } else {
                month = month - 1;
            }

            if (month < 10) {
                month = "0" + month;
            }

            if (today == 1 || today == 2 || today == 3 || today == 4 || today == 5) {
                $.ajax({
                    type: "GET",
                    url: "ra_ajax_encourage.php",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    async:false,
                    data: {method:"checkpopup", shopid:$("#shopid").val(), userid:$("#ownerid").val(), year:year, month:month},
                    success: function (data) {
                        if (data.status == 1) {
                            popupEncourage = true;
                            addscore = data.addscore;
                        } else {
                            popupEncourage=false;
                        }
                    }
                });
            }

            if (popupEncourage) {
                $("#cancel_con1").find(".userpop_body_txt2").find("span").html(addscore);
                var popupWidth =  $(".shopowner_body").width();
                var windowWidth =  $(window).outerWidth();
                var windowHeight =  $(window).outerHeight();
                var popupHeight = $("#cancel_con1").height();
                $(".pop_mask").fadeIn(500);
                $("#cancel_con1").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
            }
			//注释普通浮层弹窗    （注释或者开启）
           else {
                var popupWidth =  $(".shopowner_body").width();
                var windowWidth =  $(window).outerWidth();
                var windowHeight =  $(window).outerHeight();
                var popupHeight = $("#cancel_con2").height();
                $(".pop_mask").fadeIn(500);
                $("#cancel_con2").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
            }

            // 红包浮层判断
            $.ajax({
                type: "GET",
                url: "ra_ajax_redpocket.php",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                async:false,
                data: {method:"checkpopup", userid:$("#ownerid").val()},
                success: function (data) {
                    if (data.status == 1) {
                        var popupWidth =  $(".shopowner_body").width();
                        var windowWidth =  $(window).outerWidth();
                        var windowHeight =  $(window).outerHeight();
                        var popupHeight = $("#cancel_con3").height();
						//新添加
						var popupHeight = $("#cancel_con4").height();
						//新添加结束
                        $(".pop_mask").fadeIn(500);
                        $("#cancel_con3").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
						$("#cancel_con4").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
                        return;
                    }
                }
            });
        }
	
    </script>
</head>
<body>
<input type="hidden" id="ownerid" value="<?php echo($shoper['id'])?>" />
<input type="hidden" id="shopid" value="<?php echo($shop['id']);?>" />
<div class="shopowner_body">
    <div class="shopowner_body_con">
        <div class="shopowner_body_con_set"><a href="javascript:void(0)" id="p2_3"><img src="images/p2_3.png" /></a></div>
        <div class="shopowner_body_con_titletxt">
            <div class="shopowner_body_con_titletxt1"><?php echo $shoper['name']?></div>
            <div class="shopowner_body_con_titletxt2"><?php echo $shop['name']?></div>
        </div>
        <div class="shopowner_body_con_box1">
            <div class="shopowner_body_con_box1_inner1">合成油总销量：<?php echo $shop['sell_count']?></div>
            <div class="shopowner_body_con_box1_inner1">当前积分：<?php echo $shop['quadratic']?></div>
            <div class="shopowner_body_con_box1_inner2"><span style="overflow:hidden; width:46%">店长积分兑换商城</span>
            <a href="javascript:void(0);" id="market_list" style="margin-left:5px; width:30%">兑换记录</a>
             <a href="javascript:void(0);" id="market">兑换</a>        </div>
        </div>
        <div class="shopowner_body_con_box2">
            <div class="shopowner_body_con_box1_inner1">上月门店增长率：<?php echo($growthRate['monthcurrent'])?>%</div>
            <div class="shopowner_body_con_box1_inner1">上月门店销量：<?php echo $shop['prev_month_count']?></div>
            <div class="shopowner_body_con_box1_inner1">上月门店城市排名：<?php echo $ranking?></div>
        </div>
        <?php
            if ($inActivity) {
        ?>
                <div class="shopowner_body_con_box3">
                    <div class="shopowner_body_con_box3_inner1">本月指标:  本月门店销量达<?php echo($growthRate['purpose'])?>桶店长即可获额外积分<?php echo($growthRate['addscore'])?>分</div>
                </div>
        <?php
            }
        ?>

        <div class="shopowner_body_con_btn"><a href="clerkmana.php?id=<?php echo $shop['id']?>"><img src="images/shopowner_btn.png" />店员管理</a>
		
		</div>
        <div class="foot_txt" style="color:#7f7c7c;font-size:12px;width:100%;text-align:center;float:left;text-align:center;margin-top:20px;">本活动最终解释权归壳牌所有</div>

        <div id="p2box">
            <img class="p1bg bg" src="images/p2boxbg.png">
            <img id="p2boxbt" src="images/p2boxbt.jpg">
            <img id="p2boxbt_2" src="images/p2boxbt_2.jpg">
            <input class="ipt" id="nm" type="text" name="" value="<?php echo $shoper['name']?>">
            <input class="ipt" id="tel" type="text" name="" value="<?php echo $shoper['phone']?>">
            <input class="ipt" id="add" type="text" name="" value="<?php echo $shoper['address']?>">
            <span class="ipt" id="shop_name"><?php echo $shop['name']?></span>
        </div>
    </div>
</div>

<div class='pop_mask'style="display:none; width:100%;height:100%"></div>
<div class="userpop_body" style="display:none;" id="cancel_con1">
    <div class="userpop_body_inner">
        <div class="userpop_body_cancel"><a href="javascript:void(0)" class="cancel1"><img src="images/pop1_cancel.png" width="40" height="40" /></a></div>
        <div class="userpop_body_txt">
            <div class="userpop_body_txt1">好消息！！</div>
            <div class="userpop_body_txt2">恭喜您，您的门店本月销售业绩优异，已达本月销售目标，获得额外积分<span style="color:#ee1b22"></span>积分！可至<a href="javascript:void(0)" style="color:#f09802">个人中心</a>查看。</div>
            <div class="userpop_body_txt4">本活动最终解释权归壳牌所有</div>
        </div>
    </div>
</div>

<div class="userpop_body" style="display:none;" id="cancel_con2">
    <div class="userpop_body_inner">
        <div class="userpop_body_cancel"><a href="javascript:void(0)" class="cancel2"><img src="images/pop1_cancel.png" width="40" height="40" /></a></div>
        <div class="userpop_body_txt">
            <div class="userpop_body_txt1">系统维护通知</div>
            <div class="userpop_body_txt2">亲爱的用户您好，壳牌喜力汽车专家将于今晚21:00-24:00进入系统维护时间，期间将不能进行油品扫码、积分兑换等操作，对您造成的不便敬请谅解。</div>
            <!--<div class="userpop_body_txt3"><span>●</span>喜力HX7 - 10分</div>
            <div class="userpop_body_txt3"><span>●</span>喜力HX8 - 15分</div>
            <div class="userpop_body_txt3"><span>●</span>超凡喜力 - 20分</div>
            <div class="userpop_body_txt2">之后对于表现突出的门店，会给到店长额外的奖励，感谢大家的支持。</div>-->
        </div>
        <div class="userpop_body_btn"><a href="javascript:void(0)" class="cancel2">返回</a></div>
    </div>
</div>

<div class="userpop_body" style="display:none;" id="cancel_con3">
    <div class="userpop_body_inner">
        <div class="userpop_body_cancel"><a href="javascript:void(0)" class="cancel3"><img src="images/pop1_cancel.png" width="40" height="40" /></a></div>
        <div class="userpop_body_txt">
            <div class="userpop_body_txt1">红包活动</div>
            <div class="userpop_body_txt2">红包活动开始了，请点击菜单栏“积分验证”中的【积分红包】，领取红包即可获得随机积分！</div>
            <div class="userpop_body_txt4">本活动最终解释权归壳牌所有</div>
        </div>
    </div>
</div>


<div class="userpop_body" style="display:none;" id="cancel_con4">
    <div class="userpop_body_inner">
     
        <div class="userpop_body_txt">
        	<input type="hidden" id="activityid" value="<?php echo $activityid?>" />
			
            <div class="userpop_body_txt1"style=" border: none;"><?php echo $a?></div>
            <div class="userpop_body_txt2" ><?php echo $b?></div>
			<div class="userpop_body_btn" style="margin-left:10%">
			
				<a href="#" class="botton" dd="1" >我要参加</a>
				
			</div>
				<div class="userpop_body_btn" style="margin-left:10%">
			<a href="#" class="botton" dd="2">暂不参加</a>
			</div>
            <div class="userpop_body_txt4">本活动最终解释权归壳牌所有</div>
			
        </div>
    </div>
</div>

</body>
</html>
